package com.example.demo.entity.pojo;

import com.example.demo.utils.token.TokenDuration;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Calendar;
import java.util.Objects;

@Data
@NoArgsConstructor
public class Token {
    private Integer id;
    private Integer type;
    private long exTime;

    public Token(Integer id, Integer type, TokenDuration tokenDuration) {
        this.id = id;
        this.type = type;
        Calendar nowTime = Calendar.getInstance();
        nowTime.add(Calendar.MINUTE,tokenDuration.getDurationTime());
        this.exTime = nowTime.getTime().getTime();

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Token token = (Token) o;
        return exTime == token.exTime && Objects.equals(id, token.id) && Objects.equals(type, token.type);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, type, exTime);
    }
}
